package org.example.travel_web.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Collection;
import java.util.Collections;

@Builder
@NoArgsConstructor
@AllArgsConstructor
@Data
@Schema(description = "分页查询结果")
public class PageResult<E> {
    @Schema(description = "数据总数")
    private long total;
    @Schema(description = "当前页")
    private long current;
    @Schema(description = "每页大小")
    private long size;
    @Schema(description = "数据列表")
    private Collection<E> list;

    public static <E> PageResult<E> of(long total, long current, long size, Collection<E> list) {
        PageResult.PageResultBuilder<E> builder = PageResult.builder();
        return builder.total(total)
                .current(current)
                .size(size)
                .list(list)
                .build();
    }

    public static <E> PageResult<E> of(long total, Collection<E> list) {
        PageResult.PageResultBuilder<E> builder = PageResult.builder();
        return builder.total(total)
                .list(list)
                .build();
    }

    public static <E> PageResult<E> empty() {
        PageResult.PageResultBuilder<E> builder = PageResult.builder();
        return builder
                .list(Collections.emptyList())
                .build();
    }
}
